package com.towker.frame.controller.report;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.towker.core.page.PageModel;
import com.towker.core.page.PageNav;
import com.towker.frame.controller.BaseController;
import com.towker.frame.model.report.SellReport;
import com.towker.frame.service.report.SellReportService;

/**
 * 销售报表
 * 
 * @author daniel.yan
 * 
 */
@Controller
@RequestMapping("/manage/report/sell")
public class SellReportController extends BaseController {
	
	@Resource
	private SellReportService sellReportService;
	
	@RequestMapping("reports")
	public ModelAndView reports(){
		ModelAndView result = new ModelAndView();
		List<SellReport> sellReports = new ArrayList<SellReport>();
		result.addObject("sellReports", sellReports);
		result.setViewName("/manage/report/sell/reports.jsp");
		return result;
	}
	@RequestMapping("queryReports")
	public ModelAndView queryReports(HttpServletRequest request,HttpServletResponse response, SellReport sellReport, @RequestParam(value="page", defaultValue="1")int page) {
		Map<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		
		paramsMap.put("SOURCE_TYPE", sellReport.getSourceType());
		paramsMap.put("STAT_TIME_TYPE", sellReport.getStatTimeType());
		paramsMap.put("STAT_USER_TYPE", sellReport.getStatUserType());
		paramsMap.put("ACC_PERIOD_START", sellReport.getAccPeriodStart());
		paramsMap.put("ACC_PERIOD_END", sellReport.getAccPeriodEnd());
		paramsMap.put("START_DATE", sellReport.getStartDate());
		paramsMap.put("END_DATE", sellReport.getEndDate());
		paramsMap.put("PAGE_SIZE", 10);
		paramsMap.put("CUR_PAGE", 1);
		paramsMap.put("COUNT", 1);
		
		ModelAndView result = new ModelAndView();
		List<SellReport> sellReports = sellReportService.getReports(paramsMap);
		
		PageModel<SellReport> pageModel = new PageModel<SellReport>(page, 10, (Integer) paramsMap.get("COUNT"), sellReports);
		
		PageNav pageNav = new PageNav(request, pageModel);
		result.addObject("pageModel", pageModel);
		result.addObject("pageNav", pageNav);
		result.setViewName("/manage/report/sell/reports.jsp");
		return result;
	}
}
